package com.xyd.Biz.Impl;

import com.xyd.Biz.FatherOrderBiz;
import com.xyd.Dao.FatherOrderDao;
import com.xyd.Entity.FatherOrder;
import com.xyd.Entity.User;
import com.xyd.Util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: FatherOrderBizImpl
 * @Description:
 * @Author 余全盛
 * @Date: 2021/10/15 15:27
 */
public class FatherOrderBizImpl implements FatherOrderBiz {
    FatherOrderDao fatherOrderDao = null;

    public FatherOrderBizImpl() {
        SqlSession session = SqlSessionFactoryUtil.open();
        fatherOrderDao = session.getMapper(FatherOrderDao.class);
    }

    @Override
    public int addOrder(long fatherorderid, double sum, User user) {
        return fatherOrderDao.addOrder(fatherorderid, sum, user);
    }

    @Override
    public FatherOrder selectFatherOrderByID(long fatherOrderid) {
        return fatherOrderDao.selectFatherOrderByID(fatherOrderid);
    }

    @Override
    public List<FatherOrder> selectAllFatherorderByUser(User user) {
        return fatherOrderDao.selectAllFatherorderByUser(user);
    }

    @Override
    public int updateFatherOrderState(int state, long fatherorderid) {
        return fatherOrderDao.updateFatherOrderState(state, fatherorderid);
    }

    @Override
    public List<FatherOrder> getFatherOrderByPagesAndNameKeyWord(String userNameKeyWord,String OrderIdKeyWord, int pageSize, int pageNum) {
        Map<String,Object> map = new HashMap<>();
        map.put("userNameKeyWord",userNameKeyWord);
        map.put("OrderIdKeyWord",OrderIdKeyWord);
        map.put("pageSize",pageSize);
        map.put("pageStart",pageSize*(pageNum-1));
        return fatherOrderDao.getFatherOrderByPagesAndNameKeyWord(map);
    }

    @Override
    public int getFatherOrderCountByNameKeyWord(String userNameKeyWord,String OrderIdKeyWord) {
        Map<String,Object> map = new HashMap<>();
        map.put("userNameKeyWord",userNameKeyWord);
        map.put("OrderIdKeyWord",OrderIdKeyWord);
        return fatherOrderDao.getFatherOrderCountByNameKeyWord(map);
    }

    @Override
    public int delFatherOrderByID(long fatherOrderid) {
        return fatherOrderDao.delFatherOrderByID(fatherOrderid);
    }
}
